package com.gongj.aop.AOPProxy;

import com.gongj.aop.GongService;
import com.gongj.aop.YuanInterface;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

import java.lang.reflect.Method;

public class Main {


	public static void main(String[] args) {
		ProxyFactory proxyFactory = new ProxyFactory();

		//设置目标对象
		proxyFactory.setTarget(new GongService());
		//proxyFactory.setProxyTargetClass(true);
		//proxyFactory.setTargetClass(YuanInterface.class);
		//proxyFactory.setOptimize(true);

		//设置接口
		//proxyFactory.setInterfaces(new Class[]{YuanInterface.class});
		//proxyFactory.addAdvisor(new MyCustomizeAdvisor());
		//设置 Advice
//		proxyFactory.addAdvice(new MethodBeforeAdvice() {
//			@Override
//			public void before(Method method, Object[] args, Object target) throws Throwable {
//				System.out.println("方法之前执行");
//				//手动执行目标对象的方法
//				method.invoke(target,args);
//			}
//		});
		// 获得代理对象
		YuanInterface proxy = (YuanInterface)proxyFactory.getProxy();
		proxy.getUserInfo("原来测测");
		proxy.findById(11L);
		System.out.println(proxy.getClass().getName());
	}
}
